console.log('aaa')

/**
 * 给你一个整数数组 nums ，判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i != j、i != k 且 j != k ，同时还满足 nums[i] + nums[j] + nums[k] == 0 。请
 * 
 * 你返回所有和为 0 且不重复的三元组。
 * 
 * 注意：答案中不可以包含重复的三元组。
 * */
var threeSum = function(nums) {
    let r = []
    nums.sort((a, b) => { return a - b })
    for (let i = 0; i < nums.length - 2 && nums[i] <= 0; i++) {
        if (i > 0 && nums[i] == nums[i - 1]) {
            continue
        }
        let s = i + 1
        let e = nums.length - 1
        while(s < e) {
            const t = nums[i] + nums[s] + nums[e]
            if (t == 0) {
                r.push([nums[i], nums[s], nums[e]])
                s++
                e--
                while(nums[s] == nums[s - 1]){
                    s++
                }
                
                while(nums[e] == nums[e + 1]) {
                    e--
                }

            } else if (t > 0) {
                e--
            } else if (t < 0) {
                s++
            }
        }
        
    }
    
    return r

};

let s = threeSum([-1,0,1,2,-1,-4,-2,-3,3,0,4])
console.log(s)


var lengthOfLongestSubstring = function(s) {
    var arr = s.split('')
    var rt = 1
    var tmp = [arr[0]]
    for(let i = 1; i < arr.length; i++) {
        const index = tmp.indexOf(arr[i])
        if(index >= 0) {
            tmp.splice(0, index+1)
        }
        rt = tmp.push(arr[i])
    }
    return rt

};

let ll = lengthOfLongestSubstring('abcabcbb')
console.log(ll)


// 力扣-8 字符串轉數字
var myAtoi = function(s) {
    s = s.trim()
    s = s.split('')
    var flag = true
    var num = 0
    if (s.length) {
        let max = Math.pow(2, 30) + 1
        let min = 0 - Math.pow(2, 31)
        for(let i = 0; i < s.length; i++) {
            if (i == 0) {
                if (s[i] == '-') {
                    flag = false
                } else if(s[i] == '+') {
                    flag = true
                } else {
                    if (s[i].toString() >= '0' && s[i].toString() <= '9') {
                        num = s[i] - 0
                    } else {
                        break
                    }
                }
            } else {
                let n = s[i].toString()
                if (n >= '0' && n <= '9') {
                    if (flag) {
                        if (num * 10 > max) {
                            return max
                        } else {
                            num = num * 10 + (+n)
                        }
                    } else {
                        if (num * 10 < min) {
                            return min
                        } else {
                            num = num * 10 - (+n)
                        }
                    }
                } else {
                    break
                }

            }
        }

    }
    return num

};

let mm = myAtoi('  -42')
console.log(mm)